#!/bin/sh

MODDIR=/lib/modules

insmod $MODDIR/proton.ko

if [ -e /var/etc/.firstboot ]; then
   echo "WAIT 3 min" > /dev/vfd
   echo "WAIT 3 min"
   rm /var/etc/.firstboot
   touch /dev/.devfsd
fi

/etc/init.d/mountvirtfs start

insmod $MODDIR/e2_proc.ko

if [ ! -e /var/etc/.firstboot ]; then

   echo "Starting DEBUG Interface"
   /etc/init.d/mountall start
   /etc/init.d/hostname start

   echo "starting telnetd"
   /usr/sbin/telnetd -l /bin/login

   echo "init stmfb"
   insmod $MODDIR/stmcore-display-stx7109c3.ko
   insmod $MODDIR/stmfb.ko display0=720x576-32@60:12m:pal:yuv:yuv;# display1=720x576-16@50:1m:pal:cvbs;

   echo "LOADING MODULES"   
   echo "LOADING MODULES" >/dev/vfd

   echo "load a/v firmware"
   /bin/stslave -t stb7100.0 -R /boot/video.elf
   /bin/stslave -t stb7100.1 -R /boot/audio.elf

   echo "init embx"
   insmod $MODDIR/embxshell.ko
   insmod $MODDIR/embxmailbox.ko mailbox0=0xb9211000:136:set2 mailbox1=0xb9212000:0 ;
   insmod $MODDIR/embxshm.ko mailbox0=shm:0:7:0x60000000:0:256:256:0:1024:0xa4000000:0x10000000 ;
   insmod $MODDIR/mme_host.ko transport0=shm

   echo "init AVS"
   insmod $MODDIR/avs.ko type=stv6418

   player=`cat /proc/stb/player/version`
   if [ $player=='player179' ]; then
	echo "[rcS] init player 179"
   else
	echo "[rcS] init player 131"
   fi
   insmod $MODDIR/mmelog.ko
   insmod $MODDIR/mpeg2hw.ko mmeName=MPEG2_TRANSFORMER0;
   insmod $MODDIR/ksound.ko
   insmod $MODDIR/p2div64.ko
   insmod $MODDIR/stm_v4l2.ko
   if [ $player=='player179' ]; then
	insmod $MODDIR/stmvout.ko
	insmod $MODDIR/stmvbi.ko
   fi
   insmod $MODDIR/pseudocard.ko
   
   echo "init frontends"
   insmod $MODDIR/fe-core.ko demod=stb0899 tuner=stb6100 ;

   echo "init drivers"
   insmod $MODDIR/cimax.ko
   insmod $MODDIR/pti.ko
   if [ $player=='player179' ]; then
	insmod $MODDIR/stm_monitor.ko
	insmod $MODDIR/stmsysfs.ko
    insmod $MODDIR/stmdvb.ko
   else
    insmod $MODDIR/stmdvb.ko
    insmod $MODDIR/stm_monitor.ko
   fi	
   insmod $MODDIR/player2.ko
   insmod $MODDIR/sth264pp.ko
   insmod $MODDIR/stmalloc.ko
   insmod $MODDIR/platform.ko
   insmod $MODDIR/smartcard.ko

   showiframe -p /boot/bootlogo.mvi &
   stfbcontrol a 0

   echo "init frontpanel"
   insmod $MODDIR/boxtype.ko
   insmod $MODDIR/simu_button.ko

   echo "init lircd"
   /usr/bin/lircd

   mknod /dev/rc c 147 1 
   mknod /dev/sci0 c 169 0
   mknod /dev/sci1 c 169 1 
   
   /bin/evremote2 hl101 &

   #DVD-PLAYER EXIT-TASTE LOAD OR EJECT DVD
   #mount /dev/sr0 /media/dvd
   #fix this later if we got to manage a marusys raw device driver
   mount /dev/sda5 /hdd/

   /etc/init.d/portmap start
   /etc/init.d/vsftpd start
   /usr/sbin/inetd

   #timefix e2
   date -s "121220001970"

   stfbcontrol a 255

   echo "LOADING e2" > /dev/vfd
   echo "LOADING e2"

   until false
   do
      echo "starting e2->"
      /usr/local/bin/enigma2
      rtv=$?
      echo "e2 ended <- RTV: " $rtv
      case "$rtv" in
		0) echo "0"
		   echo "E2 ERROR"
      	   reboot;;
		1) echo "1"
		   echo "SHUTDOWN"
           umount -a;;
		2) echo "2"
		   echo "REBOOT"
		   reboot;;
		3) echo "3"
		   echo "E2 RESTART"
		   echo "0" > /proc/progress
		   showiframe -p /boot/bootlogo.mvi &;;
		*) echo "*"
		   echo "ERROR"
           reboot;;
      esac
   done 
fi

#never reached
echo "REBOOT HL101" > /dev/vfd
echo "REBOOT HL101"
reboot
